import { LogLevel, UpgradeStatus } from '../../../constants/log';
/**
 * 验证查询表单字段是否合法
 * @param {object} form 查询表单
 */
export function validateSearchForm(form) {
  if (!form.start) return '请选择查询开始时间';
  if (!form.end) return '请选择查询结束时间';
  return null;
}

/**生成系统日志级别下拉列表可选数据*/
export function generateLevelSelectorData() {
  const result = [{ value: '', label: '日志级别' }];
  Object.values(LogLevel).forEach(level => {
    result.push({ value: level, label: getLevelDisplay(level) });
  });
  return result;
}

/**生成升级状态下拉列表可选数据 */
export function generateUpgradeStatusSelectorData() {
  const statusResult = [{ value: '', label: '升级状态' }];
  Object.values(UpgradeStatus).forEach(status => {
    statusResult.push({ value: status, label: getUpgradeStatusDisplay(status)});
  });
  return statusResult;
}

/**
 * 获取日志级别显示内容
 * @param {string} level 日志级别
 */
export function getLevelDisplay(level) {
  switch (level) {
    case LogLevel.Trace:
      return '追溯';
    case LogLevel.Debug:
      return '调试';
    case LogLevel.Info:
      return '信息';
    case LogLevel.Warn:
      return '警告';
    case LogLevel.Error:
      return '错误';
    case LogLevel.Fatal:
      return '严重错误';
    default:
      return '未知级别';
  }
}

/**
 * 获取日志级别显示颜色
 * @param {string} level 日志级别
 */
export function getLevelColor(level) {
  switch (level) {
    case LogLevel.Trace:
      return '#BBBBBB';
    case LogLevel.Debug:
      return '#10aeff';
    case LogLevel.Info:
      return '#07c160';
    case LogLevel.Warn:
      return '#ffc300';
    case LogLevel.Error:
      return '#fa5151';
    case LogLevel.Fatal:
      return '#fa5151';
    default:
      return '#FFFFFF';
  }
}

/**
 * 获取升级状态显示内容
 * @param {string} status 升级状态
 */
export function getUpgradeStatusDisplay(status) {
  switch (status) {
    case UpgradeStatus.Unknown:
      return '未知';
    case UpgradeStatus.ToUpgrade:
      return '待升级';
    case UpgradeStatus.Upgraded:
      return '已升级';
    case UpgradeStatus.Disabled:
      return '已禁用';
    default:
      return '未知状态';
  }
}

/**
 * 获取升级状态显示颜色
 * @param {string} status 升级状态
 */
export function getUpgradeStatusColor(status) {
  switch (status) {
    case UpgradeStatus.Unknown:
      return '#ccc';
    case UpgradeStatus.ToUpgrade:
      return '#0070BB';
    case UpgradeStatus.Upgraded:
      return '#48BB31';
    case UpgradeStatus.Disabled:
      return '#FF0006';
    default:
      return '#ccc';
  }
}
